package com.hall.utils;

import org.apache.http.client.utils.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/*根据日程表timeconfig判断是否可约*/
public final class UserScheduleUtils {
   static Map<Date,Integer> dates=new LinkedHashMap<Date,Integer>(){{
        put(ChangeTime("08:00:00"),0);
        put(ChangeTime("09:00:00"),1);
        put(ChangeTime("10:00:00"),2);
        put(ChangeTime("11:00:00"),3);
        put(ChangeTime("14:00:00"),4);
        put(ChangeTime("15:00:00"),5);
        put(ChangeTime("16:00:00"),6);
        put(ChangeTime("17:00:00"),7);
        put(ChangeTime("18:00:00"),8);
        put(ChangeTime("20:00:00"),9);
    }
    };
    public static String checkTimeConfig(String timeconfig, String applyTime, String endTime){
        String[] s1 = applyTime.split(":");
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < s1.length; i++){
            sb.append(s1[i]);
        }
        s1[1]="00";
        Date d1 = ChangeTime(sb.toString()+":00");
        Date d2 = ChangeTime(endTime+":00");
        Iterator<Date> iter = dates.keySet().iterator();
        List<Integer> d3= new ArrayList<>();
        while (iter.hasNext()) {
            Date d = iter.next();
            if(d==d1){   //获取的当前会议开始时间的那一位timeconfig位置
                d3.add(dates.get(d));
            }
            if(d.getTime()>d2.getTime()){
                d3.add(dates.get(d));
                break;
            }
        }
        return "可约";
    }
    public static Date ChangeTime(String time) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
        Date date = null;
        try {
            date = simpleDateFormat.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
